package com.spring.demo5.eg5;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Map;

/**
 * @author vhans
 */
public class ConditionTest {
    @Test
    public void test() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig6.class);
        Map<String, String> beansOfType = context.getBeansOfType(String.class);
        // 当使用前置存在Service类型的bean的Condition条件后，发现输出为空，这是因为在配置类解析过程中，容器中是没有Service类型的bean的
        // 所以要在bean注册的阶段中判断Service是否存在才行，此时就要用到ConfigurationCondition接口了
        beansOfType.forEach((beanName, bean) -> {
            System.out.println(beanName + "->" + bean);
        });
    }

    @Test
    public void testConfigurationCondition() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig7.class);
        Map<String, String> beansOfType = context.getBeansOfType(String.class);
        beansOfType.forEach((beanName, bean) -> {
            System.out.println(beanName + "->" + bean);
        });
    }
}
